<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>用户管理</title>
<jsp:include page="../inc.jsp"></jsp:include>
<script type="text/javascript">
	var dataGrid;
	$(function() {
		dataGrid = $('#dataGrid').datagrid({
			url : '${pageContext.request.contextPath}/jkglController/dataGrid.shtml',
			fit : true,
			fitColumns : true,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'NAMESTR',
			sortOrder : 'asc',
			checkOnSelect : false,
			singleSelect:true,
			selectOnCheck : false,
			nowrap : false,
			frozenColumns : [ [ {
				field : 'JKBM',
				title : '接口编码',
				width : 250,
				sortable : true
			} ] ],
			columns : [ [ {
				field : 'NAME',
				title : '接口名称',
				width : 250,
				sortable : true
			}, {
				field : 'ZHUANGTAI',
				title : '状态',
				width : 150,
				formatter : function(value, row, index) {
					if(value==1){
						return '已开通';
					}else{
						return '未开通';
					}
				}
			}, {
				field : 'ID',
				title : '操作',
				width : 150,
				formatter : function(value, row, index) {
					var str = '';
						str += $.formatString('<img onclick="KT(\'{0}\');" src="{1}" title="开通接口"/>', row.ID, '${pageContext.request.contextPath}/style/images/extjs_icons/feed/feed_add.png');
						str += "      ";
						str += $.formatString('<img onclick="GB(\'{0}\');" src="{1}" title="关闭接口"/>', row.ID, '${pageContext.request.contextPath}/style/images/extjs_icons/feed/feed_delete.png');
					return str;			
				}
			} ] ],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');

				$(this).datagrid('tooltip');
			},
		});
	});
	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
	}
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
	}
	function deleteFun(id) {
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].ID;
		}
		parent.$.messager.confirm('询问', '您是否要删除当前选择数据？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.post('${pageContext.request.contextPath}/jkglController/delete.shtml', {
					id : id
				}, function(result) {
					if (result.success) {
						dataGrid.datagrid('reload');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}
	function editFun(id) {
		if (id == undefined) {
			var rows = dataGrid.datagrid('getSelections');
			id = rows[0].ID;
		}
		parent.$.modalDialog({
			title : '修改渠道管理',
			width : 780,
			height : 500,
			href : '${pageContext.request.contextPath}/jkglController/editPage.shtml?id=' + id,
			buttons : [ {
				text : '编辑',
				handler : function() {
					parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
					var f = parent.$.modalDialog.handler.find('#form');
					f.submit();
				}
			} ]
		});
	}
	function KT(ID) {
		parent.$.messager.confirm('询问', '您是否要开通当前渠道？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.post('${pageContext.request.contextPath}/jkglController/edit.shtml', {
					ZHUANGTAI : '1',
					ID:ID
				}, function(result) {
					if (result.success) {
						dataGrid.datagrid('reload');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}
	function GB(ID) {
		parent.$.messager.confirm('询问', '您是否要关闭当前渠道？', function(b) {
			if (b) {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				$.post('${pageContext.request.contextPath}/jkglController/edit.shtml', {
					ZHUANGTAI : '0',
					ID:ID
				}, function(result) {
					if (result.success) {
						dataGrid.datagrid('reload');
					}
					parent.$.messager.progress('close');
				}, 'JSON');
			}
		});
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 60px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" style="display: none;">
					<tr>
						<th>用户名</th>
						<td><input name="YHM_CONTAINS" placeholder="请输入用户名" class="span2" /></td>	
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_add',plain:true" onclick="searchFun();">过滤条件</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'brick_delete',plain:true" onclick="cleanFun();">清空条件</a>
	</div>
</body>
</html>